Method and device for storing time series data with adaptive length encoding

ABSTRACT

Provided are a method and device for storing time series data with adaptive length encoding, including: acquiring data values corresponding to timestamps according to a sequential order of timestamps; using a ratio of storage space values required to pre-store the previous n data values to storage space values required to pre-store rule information of a preset encoding rule and encoding data according to the previous n data values as a storage gain corresponding to the time at which the n-th data value is acquired; storing the rule information of the preset encoding rule and the encoding data corresponding to a previous n−1 data values when the storage gain corresponding to the time at which the n-th data value is acquired is less than that corresponding to the time at which the (n−1)-th data value is acquired.

CROSS-REFERENCE TO RELATED APPLICATION Technical Field

This application is a national phase entry of International ApplicationNo. PCT/CN2018/12596 filed on Dec. 12, 2018, which is based on andclaims priority to Chinese Patent Application No. 201711319331.1 filedon Dec. 12, 2017 entitled “Method and Device for Storing Time SeriesData with Adaptive Length Encoding”, which is incorporated herein byreference in its entirety.

BACKGROUND Description of the Related Art

With the continuous development and maturity of technologies such ascloud computing, the Internet, and the Internet of Things, time seriesdata occupies a large proportion in various fields and people's dailylives. The time series data is a series of data values with timestamps,arranged in ascending order of time and from the same target, such asambient temperature, stock price, memory usage rate of a machine, and soon over a period of time. It usually has the characteristics of highproduction speed and large data amount.

In many practical application scenarios, the time series data isultimately saved on a disk. Due to the large amount of data, one of theproblems at present is how to efficiently store the time series data, sothat the space of the disk can be occupied as small as possible. Thebasic idea to solve this problem is to encode the data and store theencoded data, that is, to convert the original data into another form bya specific algorithm. After this conversion, the required storage spaceis less than the original storage space. At present, a plurality ofgeneral methods have been proposed in the industrial and academic fieldsand have one thing in common, assuming that data will change accordingto certain rules. By storing these rules rather than the data itself,the storage space can be effectively reduced.

However, the storage of the encoded encoding data also gives rise to aseries of problems, some abnormal data (for example, the abnormal datavalue at some time due to the failure of the collecting device) may bepresent in the actual time series data. In this case, the encoding ofthese abnormal data usually requires a large amount of descriptiveinformation, which results in poor storage performance, and the optimalstorage space saving effect is not achieved.

BRIEF SUMMARY

In order to overcome the problems above or at least partially solve theproblems above, the present disclosure provides a method and device forstoring time series data with adaptive length encoding.

According to an aspect of the present disclosure, a method for storingtime series data with an adaptive length encoding includes: sequentiallyobtaining a data value corresponding to each timestamp according to asequential order of timestamps in the time series data; encodingprevious n data values according to a preset encoding rule, andacquiring a first encoding data corresponding to the previous n datavalues, wherein the first encoding data includes a first number ofencoding values, wherein n is an integer greater than 1; determining afirst storage space value required to pre-store the previous n datavalues, determining a second storage space value required to pre-storerule information of the preset encoding rule and the first encodingdata, using a ratio of the first storage space value to the secondstorage space value as a storage gain at a first time, wherein the firsttime is the time at which n-th data value is acquired; storing the ruleinformation of the preset encoding rule and a second encoding datacorresponding to previous n−1 data values when the storage gain at thefirst time is less than that at a second time or the first numberreaches a preset value, wherein the second time is the time at which(n−1)-th data value is acquired.

In an embodiment of the present disclosure, the encoding the previous ndata values according to the preset encoding rule, and acquiring thefirst encoding data include: performing first-order differentialprocessing on the previous n data values to acquire first-orderdifferential values; determining a reference value, and sequentiallyacquiring a difference value between each first-order differential valueand the reference value, wherein each difference value is taken as anencoding value.

In an embodiment of the present disclosure, the determining thereference value includes: using a minimum first-order differential valueamong all the first-order differential values as the reference value.

In an embodiment of the present disclosure, the determining the firststorage space value required to pre-store the previous n data valuesinclude: determining a storage space value used to pre-store each datavalue; and using a product of the storage space value used to pre-storeeach data value and n as the first storage space value.

In an embodiment of the present disclosure, the determining the secondstorage space value required to pre-store rule information of the presetencoding rule and the first encoding data includes: determining storagespace values required to pre-store the rule information; determining astorage space value required to pre-store each encoding value in thefirst encoding data and selecting a maximum value among all storagespace values required to pre-store each encoding value in the firstencoding data as a constant storage space value for pre-storing eachencoding value in the first encoding data; using a product of theconstant storage space value for pre-storing each encoding value in thefirst encoding data and the first number as storage space valuesrequired to pre-store the first encoding data, and using a sum of thestorage space values required to pre-store the rule information and thestorage space values required to pre-store the first encoding data asthe second storage space value.

In an embodiment of the present disclosure, the storing the ruleinformation of the preset encoding rule and the second encoding datacorresponding to previous n−1 data values includes: using the constantstorage space value for pre-storing each encoding value in the secondencoding data as an actual storage space value; storing a number ofencoding values in the second encoding data, a first data value, aminimum encoding value in the second encoding data and the actualstorage space value as the rule information in a data table; andsequentially storing each encoding valued in the second encoding data inthe data table according to allocated storage space, wherein eachstorage space value for allocating the occupation of the storage spaceis the actual storage space value.

In an embodiment of the present disclosure, after the storing the ruleinformation of the preset encoding rule and the second encoding datacorresponding to previous n−1 data values, the method further includes:storing n-th data value in a separate data table.

In another aspect of the present disclosure, a device for storing timeseries data with an adaptive length encoding includes: at least oneprocessor; and at least one memory communicatively connected to theprocessor, wherein: the memory stores program instructions executable bythe processor and the processor calls the program instructions toperform the methods described above.

In yet another aspect of the present disclosure, a computer programproduct is provided comprising: a computer program stored on anon-transitory computer readable storage medium, the computer programincludes program instructions enabling a computer perform the methodsdescribed above when the program instructions are executed by thecomputer.

In still another aspect of the present disclosure, the presentdisclosure provides a non-transitory computer readable storage mediumstoring computer instructions that enable the computer to performmethods described above.

A method for storing time series data with an adaptive length encodingprovided by the present disclosure includes: sequentially acquiring adata value corresponding to each timestamp according to a sequentialorder of timestamps in the time series data; encoding previous n datavalues according to a preset encoding rule, and acquiring a firstencoding data corresponding to the previous n data values, wherein thefirst encoding data includes a first number of encoding values, whereinn is an integer greater than 1; determining a first storage space valuerequired to pre-store the previous n data values, determining a secondstorage space value required to pre-store rule information of the presetencoding rule and the first encoding data, using a ratio of the firststorage space value to the second storage space value as a storage gainat a first time, wherein the first time is the time at which n-th datavalue is acquired; storing the rule information of the preset encodingrule and a second encoding data corresponding to a previous n−1 datavalues when the storage gain at the first time is less than that at asecond time or the first number reaches a preset value, wherein thesecond time is the time at which (n−1)-th data value is acquired. Duringthe encoding of the sequence of the time series data, the storage gainis introduced to determine whether abnormal data exists in the sequenceof the time series data, the encoding data corresponding to all the dataahead of the abnormal data is stored when it is determined that theabnormal data exists, thereby avoiding the adverse effect caused by theabnormal data in the encoding process, and ensuring the optimal storagespace saving effect.

BRIEF DESCRIPTION OF THE DRAWINGS

In order to more clearly illustrate the technical solutions disclosed inthe present disclosure or the prior art, the drawings used in thedescriptions of the embodiments or the prior art will be brieflyintroduced below. Obviously, the drawings in the following descriptionare only certain embodiments of the present disclosure, and otherdrawings can be obtained according to these drawings without anycreative work for those skilled in the art.

FIG. 1 is a flowchart of a method for storing time series data withadaptive length encoding in accordance with an embodiment of the presentdisclosure; and

FIG. 2 is a schematic diagram of a data structure of a data table inaccordance with an embodiment of the present disclosure.

DETAILED DESCRIPTION

In order to make the objectives, technical solutions and advantages ofthe present disclosure more clear, the technical solutions in theembodiments of the present disclosure are clearly and completelydescribed in the following with reference to the accompanying drawingsin the present disclosure. Obviously, the described embodiments are apart of the embodiments of the present disclosure, but not all of theembodiments. All other embodiments obtained by a person of ordinaryskill in the art based on the embodiments of the present disclosurewithout any creative work belong to the scope of the present disclosure.

In an embodiment of the present disclosure, referring to FIG. 1, amethod for storing time series data with an adaptive length encoding isprovided, including: S11, sequentially acquiring a data valuecorresponding to each timestamp according to a sequential order oftimestamps in the time series data; S12, encoding previous n data valuesaccording to a preset encoding rule, and acquiring a first encoding datacorresponding to the previous n data values, wherein the first encodingdata includes a first number of encoding values, wherein n is an integergreater than 1; S13, determining a first storage space value required topre-store the previous n data values, determining a second storage spacevalue required to pre-store rule information of the preset encoding ruleand the first encoding data, using a ratio of the first storage spacevalue to the second storage space value as a storage gain at a firsttime, wherein the first time is the time at which the n-th data value isacquired; S14, storing the rule information of the preset encoding ruleand a second encoding data corresponding to previous n−1 data valueswhen the storage gain at the first time is less than that at a secondtime or the first number reaches a preset value, wherein the second timeis the time at which the (n−1)-th data value is acquired.

Specifically, the time series data is a series of data values withtimestamps, arranged in ascending order of time and from the sametarget. For the time series data, a data value corresponding to eachtimestamp according to a sequential order of timestamps in the timeseries data is sequentially obtained when the time series data isstored, and n data values are encoded according to the preset encodingrule when the n data values have been acquired, so as to acquireencoding data. The storage gain is introduced in this embodiment and isa ratio of storage space values required to pre-store all data values toa total storage space value required to pre-store the encoding data andrule information of preset encoding rules; since encoding information ofthe preset encoding rule needs to be attached to facilitate decodingwhen the encoding data is stored, it is necessary to store the ruleinformation of the corresponding encoding rule when the encoding data isstored and thus the required storage space value is the sum of thestorage space values required to store the rule information of thepreset encoding rule and the storage space values required to store theencoding data.

The storage gain corresponding to the time at which the n-th data valueis acquired is compared with that corresponding to the time at which the(n−1)-th data value is acquired, it is illustrated that the n-th datavalue brings about a decrease in the storage gain and is likely to be anabnormal data value when the storage gain corresponding to the time atwhich the n-th data value is acquired is less than that corresponding tothe time at which the (n−1)-th data value is acquired, and moreinformation is needed to describe the abnormal data in the encodingprocess, resulting in the need for more storage space, so that thestorage gain is reduced. Therefore, in the actual storage, it isnecessary to exclude the influence of the storage gain drop caused bythe n-th data value, and only the rule information of the presetencoding rule and encoding data corresponding to the previous n−1 datavalues are stored. In addition, the encoding data currently acquired bythe rule information of the preset encoding rule may be stored in orderto avoid data overflow, when the number of encoding values in theencoding data reaches a preset value.

According to the present embodiment, during the encoding of the sequenceof the time series data, the storage gain is introduced to determinewhether abnormal data exists in the sequence of the time series data,the encoding data corresponding to all the data ahead of the abnormaldata is stored when it is determined that the abnormal data exists,thereby avoiding the effect of storage gain drop caused by the abnormaldata in the encoding process, and ensuring the optimal storage spacesaving effect.

Based on the embodiments above, the encoding the previous n data valuesaccording to the preset encoding rule, and acquiring the first encodingdata include: performing first-order differential processing on theprevious n data values to acquire first-order differential values;determining a reference value, and sequentially acquiring a differencevalue between each first-order differential value and the referencevalue, wherein each difference value is taken as an encoding value.

In an embodiment of the present disclosure, the determining thereference value includes: using a minimum first-order differential valueamong all the first-order differential values as the reference value.

Specifically, for the previous n data values, first-order differentialvalues between each data value and data values ahead of each data valueare acquired in a first-order differential manner, and then a referencevalue is determined, each first-order differential value and thereference value are differenced to acquire a difference value as oneencoding value; by selecting a minimum value in all the first-orderdifferential values as the reference value, the differences between eachfirst-order differential value and the reference value are non-negativenumbers, that is, all encoding values are non-negative numbers; sincethe stored data needs to be converted into binary code, the encodingvalues are non-negative numbers, so that binary transcoding can beperformed in the storage process.

Based on the embodiments above, the determining the first storage spacevalue required to pre-store the previous n data values includes:determining a storage space value used to pre-store each data value; andusing a product of the storage space value used to pre-store each datavalue and n as the first storage space value.

Specifically, when the time series data is stored, for the same sequenceof data, each data is stored in the same storage space to facilitatereading, writing and managing, and the data value is stored withoutattaching any description information and thus storage space valuesrequired to pre-store the data values is a product of the storage spacevalue used to pre-store each data value and the number (n) of the datavalues.

Based on the embodiments above, the determining the second storage spacevalue required to pre-store rule information of the preset encoding ruleand the first encoding data includes: determining storage space valuesrequired to pre-store the rule information; determining a storage spacevalue required to pre-store each encoding value in the first encodingdata and selecting a maximum value among all storage space valuesrequired to pre-store each encoding value in the first encoding data asa constant storage space value for pre-storing each encoding value inthe first encoding data; using a product of the constant storage spacevalue for pre-storing each encoding value in the first encoding data andthe first number as storage space values required to pre-store the firstencoding data, and using a sum of the storage space values required topre-store the rule information and the storage space values required topre-store the first encoding data as the second storage space value.

Specifically, since the data needs to be converted into a binary code asbeing stored, the size of the encoding values can determine its storagespace values. For example, the binary code of the decimal value “10” is“1010”, which requires 4 bits of storage space, and the binary code of adecimal value 2 is “10” which only requires 2 bits of storage space. Thestorage space occupied by each encoding value after being converted intobinary code may not be the same. In order to completely store allencoding values without loss of information, a maximum value among thestorage space values required to store each encoding value should beselected as an actual storage space value for storing each encodingvalue and a product of the actual storage space value and the number ofthe encoding values is used as the storage space value required to storethe encoding data. Since encoding information of the preset encodingrule needs to be attached when the encoding data is stored, it is alsonecessary to calculate the storage space value required to store theencoding information of the preset encoding rule; therefore, when thestorage gain is calculated, the influence of storage space valuesrequired to store the encoding information of the preset encoding ruleneeds to be considered, and the storage gain is calculated according tothe sum of the storage space values required to store the encoding dataand the storage space values required to store the rule information ofthe preset encoding rule.

Based on the embodiments above, the storing the rule information of thepreset encoding rule and the second encoding data corresponding toprevious n−1 data values includes: using the constant storage spacevalue for pre-storing each encoding value in the second encoding data asthe actual storage space value; storing the number of encoding values inthe second encoding data, a first data value, a minimum encoding valuein the second encoding data and the actual storage space value as therule information in a data table; and sequentially storing each encodingvalued in the second encoding data in the data table according toallocated storage space, wherein each storage space value for allocatingthe occupation of the storage space is the actual storage space value.

Specifically, the rule information of the preset encoding rule and theencoding data corresponding to the previous n−1 data values are storedin a data table, and the data structure diagram of the data table isshown in FIG. 2. The data table includes a header and a body; the headeris configured to store the rule information of the preset encoding rule,specifically including the number (number) of the encoding values storedin the data table, the first data value (firstValue), the minimumencoding value (minDelta) and the actual storage space value (Bmax)required to store each encoding value; the body is configured to storethe encoding data (Encoding data), the storage spaces occupied by eachencoding value are the same and the actual storage space values requiredto store each encoding values.

Based on the embodiments above, after the storing the rule informationof the preset encoding rule and the second encoding data correspondingto previous n−1 data values, the method further includes: storing then-th data value in a separate data table.

Specifically, since the storage gain is reduced, it is illustrated thatthe n-th data value is likely to be abnormal data, and this data valueis stored in a separate data table, so as to avoid the influence of thisdata value on other data values in the term of storage space savingeffect. Since there is only one data value, only “1, firstValue, 0, 0”are stored in the separate data table, wherein firstValue is the n-thdata value, and since there is no encoding data, the body portion in theseparate data table is empty.

As still another embodiment of the present disclosure, a device forstoring time series data with an adaptive length encoding is provided,including: at least one processor; and at least one memorycommunicatively connected to the processor, wherein: the memory storesprogram instructions executable by the processor, the processor callsthe program instructions to perform the methods provided in each of themethod embodiments above, for example, including: sequentially acquiringa data value corresponding to each timestamp according to a sequentialorder of timestamps in the time series data; encoding previous n datavalues according to a preset encoding rule, and acquiring a firstencoding data corresponding to the previous n data values, wherein thefirst encoding data includes a first number of encoding values, whereinn is an integer greater than 1; determining a first storage space valuerequired to pre-store the previous n data values, determining a secondstorage space value required to pre-store rule information of the presetencoding rule and the first encoding data, using a ratio of the firststorage space value to the second storage space value as a storage gainat a first time, wherein the first time is the time at which the n-thdata value is acquired; storing the rule information of the presetencoding rule and a second encoding data corresponding to previous n−1data values when the storage gain at the first time is less than that ata second time or the first number reaches a preset value, wherein thesecond time is the time at which the (n−1)-th data value is acquired.

As still another embodiment of the present disclosure, a computerprogram product is provided, including a computer program stored on anon-transitory computer readable storage medium, the computer programincluding program instructions. When the program instructions areexecuted by a computer, the computer is able to perform the methodsprovided by the foregoing method embodiments, for example, including:sequentially acquiring a data value corresponding to each timestampaccording to a sequential order of timestamps in the time series data;encoding previous n data values according to a preset encoding rule, andacquiring a first encoding data corresponding to the previous n datavalues, wherein the first encoding data includes a first number ofencoding values, wherein n is an integer greater than 1; determining afirst storage space value required to pre-store the previous n datavalues, determining a second storage space value required to pre-storerule information of the preset encoding rule and the first encodingdata, using a ratio of the first storage space value to the secondstorage space value as a storage gain at a first time, wherein the firsttime is the time at which the n-th data value is acquired; storing therule information of the preset encoding rule and a second encoding datacorresponding to previous n−1 data values when the storage gain at thefirst time is less than that at a second time or the first numberreaches a preset value, wherein the second time is the time at which the(n−1)-th data value is acquired.

As yet still another embodiment of the present disclosure, anon-transitory computer readable storage medium is provided storing acomputer program that causes a computer to perform the methods providedby the foregoing method embodiments, for example, including:sequentially acquiring a data value corresponding to each timestampaccording to a sequential order of timestamps in the time series data;encoding previous n data values according to a preset encoding rule, andacquiring a first encoding data corresponding to the previous n datavalues, wherein the first encoding data includes a first number ofencoding values, wherein n is an integer greater than 1; determining afirst storage space value required to pre-store the previous n datavalues, determining a second storage space value required to pre-storerule information of the preset encoding rule and the first encodingdata, using a ratio of the first storage space value to the secondstorage space value as a storage gain at a first time, wherein the firsttime is the time at which the n-th data value is acquired; storing therule information of the preset encoding rule and a second encoding datacorresponding to previous n−1 data values when the storage gain at thefirst time is less than that at a second time or the first numberreaches a preset value, wherein the second time is the time at which the(n−1)-th data value is acquired.

It can be understood by a person skilled in the art that all or part ofthe steps of implementing the method embodiments above may be completedby using hardware related to computer program instructions. Theforegoing computer program may be stored in a computer readable storagemedium, and the program performs foregoing steps including the methodembodiments above when being executed. The foregoing storage mediumincludes: a medium that can store program codes, such as a ROM, a RAM, amagnetic disk, or an optical disk.

Through the description of the embodiments above, those skilled in theart can clearly understand that the various embodiments can beimplemented by means of software and a necessary general hardwareplatform, and of course, by hardware. Based on such understanding, thetechnical solutions of the present disclosure or a part of the technicalsolutions, which is essential or contributes to the prior art, may beembodied in the form of a software product, which is stored in a storagemedium such as ROM/RAM, magnetic Discs, optical discs, etc., includingseveral instructions to enable a computer device (which may be apersonal computer, a server, or a network device, etc.) to perform thevarious embodiments or a part of the methods described in the variousembodiments.

Finally, it should be noted that the above embodiments are only used toexplain but not to limit the technical solutions of the presentdisclosure. Although the present disclosure is described in detail withreference to the foregoing embodiments, it should be understood by thoseskilled in the art that they can still modify the technical solutionsdescribed in the foregoing embodiments or make equivalent replacementsto a part of the technical features, and these modifications orsubstitutions do not depart from the spirit and scope of the technicalsolutions of the embodiments of the present disclosure.

The invention claimed is:
 1. A method for storing time series data withadaptive length encoding, comprising: sequentially acquiring a datavalue corresponding to each timestamp according to a sequential order oftimestamps in the time series data; encoding previous n data valuesaccording to a preset encoding rule, and acquiring a first encoding datacorresponding to the previous n data values, wherein the first encodingdata comprises a first number of encoding values, wherein n is aninteger greater than 1; determining a first storage space value requiredto pre-store the previous n data values, determining a second storagespace value required to pre-store rule information of the presetencoding rule and the first encoding data, using a ratio of the firststorage space value to the second storage space value as a storage gainat a first time, wherein the first time is the time at which n-th datavalue is acquired; corresponding to a previous n−1 data values when thestorage gain at the first time is less than that at a second time or thefirst number reaches a preset value, wherein the second time is the timeat which (n−1)-th data value is acquired.
 2. The method of claim 1,wherein the encoding the previous n data values according to the presetencoding rule, and acquiring the first encoding data comprise:performing first-order differential processing on the previous n datavalues to acquire first-order differential values; and determining areference value, and sequentially acquiring a difference value betweeneach first-order differential value and the reference value, whereineach difference value is taken as an encoding value.
 3. The method ofclaim 2, wherein the determining the reference value comprises: using aminimum first-order differential value among all the first-orderdifferential values as the reference value.
 4. The method of claim 1,wherein the determining the first storage space value required topre-store the previous n data values comprises: determining a storagespace value used to pre-store each data value; and using a product ofthe storage space value used to pre-store each data value and n as thefirst storage space value.
 5. The method of claim 1, wherein thedetermining the second storage space value required to pre-store ruleinformation of the preset encoding rule and the first encoding datacomprises: determining storage space values required to pre-store therule information; determining a storage space value required topre-store each encoding value in the first encoding data, and selectinga maximum value among all storage space values required to pre-storeeach encoding value in the first encoding data as a constant storagespace value for pre-storing each encoding value in the first encodingdata; and using a product of the constant storage space value forpre-storing each encoding value in the first encoding data and the firstnumber as storage space values required to pre-store the first encodingdata, and using a sum of the storage space values required to pre-storethe rule information and the storage space values required to pre-storethe first encoding data as the second storage space value.
 6. The methodof claim 1, wherein the storing the rule information of the presetencoding rule and the second encoding data corresponding to previous n−1data values comprises: using the constant storage space value forpre-storing each encoding value in the second encoding data as an actualstorage space value; storing a number of encoding values in the secondencoding data, a first data value, a minimum encoding value in thesecond encoding data and the actual storage space value as the ruleinformation in a data table; and sequentially storing each encodingvalued in the second encoding data in the data table according toallocated storage space, wherein each storage space value for allocatingthe occupation of the storage space is the actual storage space value.7. The method of claim 1, wherein after the storing the rule informationof the preset encoding rule and the second encoding data correspondingto previous n−1 data values, the method further comprises: storing n-thdata value in a separate data table.
 8. A device for storing time seriesdata with adaptive length encoding, comprising: at least one processor;and at least one memory communicatively connected to the processor,wherein: the memory stores program instructions executable by theprocessor, the processor calls the program instructions to perform themethod of claim
 1. 9. A computer program product, comprising: a computerprogram stored on a non-transitory computer readable storage medium, thecomputer program comprising program instructions enabling a computer toperform the method of claim 1, when the program instructions areexecuted by the computer.
 10. A non-transitory computer readable storagemedium storing computer programs that enable a computer to perform themethod of claim 1.